package cn.cpf.aop.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public abstract class AnnotationProxy {

    abstract protected void println(String string);

    @Pointcut("execution(* cn.cpf.aop.annotation.AnnotationProxyObjectDemo.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void before() {
        println(" before no args ");
    }

    @After("execution(* cn.cpf.aop.annotation.AnnotationProxyObjectDemo.*(..))")
    public void after() {
        println(" after ");
    }

    @AfterReturning(returning = "rst", value = "pointCut()")
    public void afterReturn(Object rst) {
        println(" afterReturn ");
    }

    @AfterThrowing(throwing = "e", value = "pointCut()")
    public void afterThrow(Throwable e) {
        println(" afterThrow " + e.toString());
    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint pjp) {
        println(" around start ");
        try {
            pjp.proceed();
        } catch (Throwable throwable) {
            println(" around throwable ");
            throw new RuntimeException("");
        }
        println(" around end ");
    }
}
